package com.code.bolg.controller;

import com.code.bolg.bean.Comment;
import com.code.bolg.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * comment
 *
 * @author  2018-10-12
 */
//@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 新增或编辑
     */
    @PostMapping("/saveOrUpdate")
    public Comment save(Comment comment) {
        return commentService.save(comment);
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    public int delete(int id) {
        return commentService.deleteById(id);
    }

    /**
     * 查询
     */
    @GetMapping("/find")
    public Comment find(int id) {
        Comment comment = commentService.findById(id);
        return comment;
    }

    /**
     * 分页查询
     */
    @PostMapping("/list")
    public List<Comment> list(Comment comment,
                       @RequestParam(required = false, defaultValue = "0") int page,
                       @RequestParam(required = false, defaultValue = "10") int size) {
        List<Comment> list = commentService.findAll(comment, page-1==-1?0:page, size);
        return list;
    }

}

